package com.neuedu.service.test;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;

import com.neuedu.live.service.Box;

public class SocketClient {

	private Socket socket;
	private ObjectOutputStream out;
	private ObjectInputStream in;
	
	public SocketClient(String addre) {
		try {
			this.socket=new Socket(addre,9100);
			
			InputStream inputstream=this.socket.getInputStream();
			OutputStream outputstream=this.socket.getOutputStream();
			
			this.in=new ObjectInputStream(inputstream);
			this.out=new ObjectOutputStream(outputstream);
			
			ArrayList<Box> list1=new ArrayList<>();
			
			ArrayList<Box> list2=new ArrayList<>();
			for (int i = 0; i < 6; i++) {
				Box box=(Box) in.readObject();
				if(box.getCode()==Box.FULL_IMAGE) {
					list1.add(box);
				}else if(box.getCode()==Box.MINI_IMAGE) {
					list2.add(box);
				}
				
			}
			for (Box b : list1) {
				System.out.println(b.getMsg());
			}
			
			for (Box b : list2) {
				System.out.println(b.getMsg());
			}
			
			
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				socket.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	public static void main(String[] args) {
		new SocketClient("10.25.193.2");
	}
}
